package com.ftg.learn.bus.role.controller;

import com.ftg.learn.bus.role.entity.Role;
import com.ftg.learn.bus.role.service.RoleService;
import com.ftg.learn.bus.util.ResultType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value = "角色信息",tags = "角色信息")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ApiOperation(value = "查所有角色")
    @GetMapping("/showrole")
    public List<Role> showAll(){
        return roleService.showAll();
    }

    @ApiOperation(value = "查一角色")
    @PutMapping("/rolefindone/{id}")
    public Role findOne(@ApiParam("角色id") @PathVariable String id){
        return roleService.findOne(id);
    }

    @ApiOperation(value = "添加角色")
    @PostMapping("/roleinsert")
    public int insert(Role role){
        return roleService.insert(role);
    }

    @ApiOperation(value = "修改一角色")
    @PostMapping("/roleupdate")
    public int update(Role role){
        return roleService.update(role);
    }

    @ApiOperation(value = "删除一角色")
    @DeleteMapping("/roledelete/{role_id}")
    public int delete(@ApiParam("角色id") @PathVariable String role_id){
        return roleService.delete(role_id);
    }

    @GetMapping("/showrole/modify&limit/{page}&{limit}&{role_id}&{role_name}")
    @ApiOperation("模糊查询与分页")
    public ResultType<Role> query(@ApiParam("总页数") @PathVariable int page, @ApiParam("每页条数") @PathVariable int limit, @ApiParam("角色id") @PathVariable String role_id, @ApiParam("角色名称") @PathVariable String role_name) {
        return roleService.query(page, limit, role_id, role_name);
    }

    @DeleteMapping("/showrole/deletes/{role_ids}")
    @ApiOperation("根据角色id 多条删除")
    public int deletes(@ApiParam("角色id(多条)") @PathVariable List<String> role_ids){
        return roleService.deletes(role_ids);
    }

}
